<template>
  <el-container class="home_con">
    <!-- 头部区域 -->
    <el-header>
      <div class="header_wrap">
        <img src="../assets/heima.png" alt="" />
        <span>拼搏百日我要上北大</span>
      </div>
      <el-button type="info" @click="Loginout">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏区域 -->
      <el-aside :width="isActive? '65px' : '200px'">
        <div class="chang_mode" @click="chang_mode">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          :unique-opened="true"
          :collapse="isActive"
          :collapse-transition="false"
          :router="true"
          :default-active="activepath"
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item1.id + ''" v-for="item1 in Left_List" :key="item1.id">
            <!-- 一级菜单区域 -->
            <template slot="title">
              <i :class="icon_List[item1.id]"></i>
              <span>{{ item1.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item @click="save_path('/'+item2.path)" :index="'/'+item2.path" v-for="item2 in item1.children" :key="item2.id">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ item2.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { getmenu } from "@/api/login";
export default {
  data() {
    return {
      Left_List: [],
      icon_List: {
        125: "iconfont iconyonghuguanli",
        103: "iconfont iconquanxianguanli",
        101: "iconfont iconshangpinguanli",
        102: "iconfont icondingdanguanli",
        145: "iconfont iconshujutongji-datastatistics",
      },
      isActive: false,
      activepath:""
    };
  },
  created() {
    this.Get_left_List();
    this.activepath=window.sessionStorage.getItem("path")
  },
  methods: {
    Loginout() {
      window.sessionStorage.clear();
      this.$router.push("/Login");
    },
    // 左侧菜单
    Get_left_List() {
      getmenu().then((res) => {
        console.log(res);
        if (res.status == 200) {
          this.Left_List = res.data.data;
          console.log(this.Left_List);
        } else {
          this.$message.error(res.data.meta.msg);
        }
      });
    },
    // 改变左侧菜单结构
    chang_mode() {
      this.isActive = !this.isActive;
    },
    // 保存路径
    save_path(path){
      window.sessionStorage.setItem("path",path)
      this.activepath=path
    }
  },
};
</script>

<style Lang="less" scoped>
.chang_mode {
  background-color: #4a5064;
  padding: 5px 0;
  color: #fff;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.2em;
  display: flex;
  cursor: pointer;
}
.el-header {
  background-color: #373d41;
}
.el-menu {
  border-right: none;
}
.el-aside {
  background-color: #333744;
}
.el-main {
  background-color: #eaedf1;
}
.home_con {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header_wrap {
  display: flex;
  align-items: center;
}
.header_wrap span {
  padding: 0 20px;
  font-size: 28px;
  color: #fff;
  font-weight: 600;
}
.el-submenu .iconfont {
  color: #fff;
}
.el-submenu span {
  padding: 0 10px;
}
</style>